package org.nf.db.util.result;

import org.nf.db.util.ResultSetHandler;
import org.nf.db.util.RowProcessor;

import java.sql.ResultSet;
import java.sql.SQLException;

/**
 * @author wangl
 * @date 2021/7/29
 */
public class BeanHandler<T> implements ResultSetHandler<T> {

    /**
     * Bean的Class对象
     */
    private final Class<T> beanClass;

    public BeanHandler(Class<T> beanClass) {
        this.beanClass = beanClass;
    }

    @Override
    public T handle(ResultSet rs) throws SQLException {
        return rs.next() ? RowProcessor.toBean(rs, beanClass) : null;
    }
}
